﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using OSA.Policlinic.UI.WFAplication.DoctorWCF.RegistryServiceReference;

namespace OSA.Policlinic.UI.WFAplication.DoctorWCF
{
    public partial class Form1 : Form
    {
        private IRegistryBusinessApplication registryBusinessApplication;
        private List<Ticket> listOfTicket;
        private Doctor customDoctor;
        public Form1(Doctor doctor)
        {
            InitializeComponent();
            registryBusinessApplication = RegistryBusinessApplicationHome.GetInstanse();
            customDoctor = doctor;
            listOfTicket=new List<Ticket>();
            listOfTicket.AddRange(registryBusinessApplication.GetTicketsByDoctor(customDoctor));
            ticketBindingSource.DataSource = listOfTicket;
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(registryBusinessApplication.IsNewTickedAdded(customDoctor))
            {
                timer1.Stop();
                MessageBox.Show("Поступили Пациэнты!!!!");
                listOfTicket = new List<Ticket>();
                listOfTicket.AddRange(registryBusinessApplication.GetTicketsByDoctor(customDoctor));
                ticketBindingSource.DataSource = listOfTicket;
                ticketDataGridView.Refresh();
                timer1.Start();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            ChooseDoctor ch = new ChooseDoctor();
            ch.ShowDialog();
            this.customDoctor = ch.choosedDoctor;
            listOfTicket = new List<Ticket>();
            listOfTicket.AddRange(registryBusinessApplication.GetTicketsByDoctor(customDoctor));
            ticketBindingSource.DataSource = listOfTicket;
            timer1.Start();
        }

    }
}
